#include "queue.hpp"

void *Consumer(void *args)
{
    BlockQueue<int> *bq = static_cast<BlockQueue<int> *>(args);

    while (true)
    {
        int t = bq->pop();//消费者消费数据
        cout<<"消费者拿到一个数据"<<t<<endl;
        sleep(1);
    }
}

void *Productor(void *args)
{
    BlockQueue<int> *bq = static_cast<BlockQueue<int> *>(args);
    int num = 0;
    while (true)
    {
        bq->push(num);//生产者生产数据
        cout<<"生产者生产一个数据"<<num<<endl;
        num++;
    }
}

int main()
{
    BlockQueue<int> *bq = new BlockQueue<int>();
    pthread_t c, p;
    pthread_create(&c, nullptr, Consumer, bq);
    pthread_create(&p, nullptr, Productor, bq);

    pthread_join(c, nullptr);
    pthread_join(p, nullptr);
    
    delete bq;
    return 0;
}